package com.zbp.config.swagger;


import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.RequestParameterBuilder;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.ParameterType;
import springfox.documentation.service.RequestParameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;
import java.util.List;

/**
 * packageName com.zbp.config.swagger
 *
 * @author zbp
 * @version JDK 8
 * @fileName SwaggerConfig.java
 * @date 2023-11-16
 * @description *Swagger3API文档的配置
 * * knife4j文档地址(端口号根据自己项目配置)： http://localhost:8080/doc.html#
 * * swagger文档地址(端口号根据自己项目配置)：http://localhost:8080/swagger-ui/index.html#/
 */
@Configuration
@EnableOpenApi
@EnableKnife4j
public class SwaggerConfig {

    /**
     * 启动Jwt授权
     *
     * @return 授权信息
     */
    public List<RequestParameter> globalRequestParameters() {
        RequestParameter token = new RequestParameterBuilder()
                .name("Authorization") // 设置header名称
                .in(ParameterType.HEADER) // 设置参数放在哪个地方，这里是header
                .required(true) // 设置是否必须传
                .build();
        List<RequestParameter> parameters = new ArrayList<>();
        parameters.add(token);
        return parameters;
    }

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.OAS_30)
                .groupName("00-用户信息")
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.zbp.web"))
                .paths(PathSelectors.any())
                .build()
                .globalRequestParameters(globalRequestParameters());
    }


    @Bean
    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("SwaggerUI接口文档")
                .description("接口文档Swagger-Bootstrap版")
                .termsOfServiceUrl("http://localhost:8080/swagger-ui/index.html#/")
                .contact(new Contact("zbp", "http://localhost:8080/doc.html#", "ideazbp@163.com"))
                .version("1.0")
                .license("zbp")
                .build();
    }
}